$(function() {
    if(!window.ActiveXObject){
        $("#footht").css("height","20px");
    }
    
    initUser();
    initPanelHeight();
    initZYbg();
	$(window).resize(function() {
			    initZYbg();
			   });
	    });
function initZYbg(){ 
	//alert(document.body.clientWidth);
     if(document.body.clientWidth<957){
	        $("#mainleft").width(0);
	        $("#mainright").width(0);
	        $("#mainleft").css("display","none");
		    $("#mainright").css("display","none");
        }else{
	       if(!window.ActiveXObject){
			        var wid=($(document).width()-953)/2;
			        $("#mainleft").width(wid);
			        $("#mainright").width(wid);
			        $("#mainleft").css("display","block");
			        $("#mainright").css("display","block");
		    }else{
		        var wid=($(document).width()-974)/2;
		        if(wid>0){
		        	$("#mainleft").width(wid);
			        $("#mainright").width(wid);
			        $("#mainleft").css("display","block");
			        $("#mainright").css("display","block");
		        }
		    }
        }
}
function initPanelHeight(){
	if(scorecount>3){
		var height=(scorecount-3)*35+600;
		$("#tgTXT").height(height);
	}
}
function initUser(){
	if(uid>0){
		SelfDwr.getUser(uid,function(data){
		if(data!=null){
			$("#tel").val(data.tel);
			$("#email").val(data.email);
			$("#address").val(data.address);
			if(data.tel.length>0){
				$("#utel").html(data.tel);
			}else{
				$("#utel").html("暂无");
			}
			if(data.email.length>0){
				$("#uemail").html(data.email);
			}else{
				$("#uemail").html("暂无");
			}
			if(data.address.length>0){
				$("#uaddress").html(data.address);
			}else{
				$("#uaddress").html("暂无");
			}
		 }
	   });
	}
}
function openBgEdit(obj){
	//加载遮罩
	var heights=document.body.clientHeight;
	var bW=$("body").width();
	if(window.ActiveXObject){
	  bW=$("body").width()-22;
    }
	$("#fullbg").css({width:bW,height:heights+"px",display:"block"});
	$("#"+obj).css({display:"block"});
	return false;
}
function closeEdit(){
	$("#fullbg").css({display:"none"});
	$("#editpanel").css({display:"none"});
	$("#edittbl").css({display:"none"});
	$("#selftbl").css({display:"none"});
}
function editSelf(){
	SelfDwr.getUser(uid,function(data){
		if(data!=null){
			$("#tel").val(data.tel);
			$("#email").val(data.email);
			$("#address").val(data.address);
		}
	});
	$("#selftbl").css({display:""});
	openBgEdit("editpanel");
}
function editPwd(){
	$("#edittbl").css({display:""});
	openBgEdit("editpanel");
}
function UpdatePwd(){
	var oldpwd = $("#oldpwd").val();
	var pwd = $("#pwd").val();
	var repwd = $("#repwd").val();
	if(oldpwd.length<1){
		alert("旧密码不能为空！");
		return false;
	}
	if(pwd.length<1){
		alert("新密码不能为空！");
		return false;
	}
	if(repwd.length<1){
		alert("确认密码不能为空！");
		return false;
	}
	if(pwd!=repwd){
		alert("两次输入密码不一样！");
		return false;
	}
	SelfDwr.UpdatePwd(uid,oldpwd,pwd,function(data){
		if(data==0){
			alert("修改失败！");
		}else if(data==1){
			alert("修改成功！");
			$("#oldpwd").val("");
	        $("#pwd").val("");
	        $("#repwd").val("");
	        closeEdit();
		}else{
			alert("旧密码不正确！");
			$("#oldpwd").val("");
		}
	});
}
function UpdateSelf(){
	var tel = $("#tel").val();
	var email = $("#email").val();
	var address = $("#address").val();
	if(tel.length>0){
	 if(!IsTelephone(tel)){
	    	alert("电话格式不正确！请填写手机或者座机号码。");
	   }
	}
	if(email.length>0){
	 if(!IsEmail(email)){
		alert("邮箱格式不正确！");
	 }
	}
	if(tel.length>0||email.length>0||address.length>0){
		SelfDwr.UpdateSelf(uid,tel,email,address,function(data){
			if(data==0){
			 alert("修改失败！");
			}else if(data==1){
				alert("修改成功！");
				$("#tel").val("");
		        $("#email").val("");
		        $("#address").val("");
		        closeEdit();
		        initUser();
			}
		});
	}else{
		alert("请填写相关信息！");
	}
}
